// DatabaseInfo.cpp: implementation of the DatabaseInfo class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "DatabaseInfo.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

namespace PDMS
{
	namespace PDMSDBIF
	{
		BEGIN_REGISTER_MAP( DatabaseInfo, DatabaseElement )
			REGISTER( _T("DBInfo") , GET_REGISTER( DatabaseElementFactory, Design_VersionOne ) )
		END_REGISTER_MAP();

		DatabaseInfo::DatabaseInfo()
		{
			
		}
		
		DatabaseInfo::~DatabaseInfo()
		{
			
		}
		
		StdString DatabaseInfo::GetOpenSQL( const StdString& strCondition )
		{
			ASSERT( !strCondition.IsEmpty() );

			return StdString( _T("Select * from DBInfo") );
		}
		
		unsigned long DatabaseInfo::GetVersion()
		{
			ASSERT( m_ResPtr != NULL );

			return m_ResPtr->GetLong( _T("version") );
		}
		
		unsigned long DatabaseInfo::GetWorldID()
		{
			ASSERT( m_ResPtr != NULL );
			
			return m_ResPtr->GetLong( _T("WorldID") );
		}
		
		unsigned long DatabaseInfo::GetDBID()
		{
			ASSERT( m_ResPtr != NULL );
			
			return m_ResPtr->GetLong( _T("DBID") );
		}
		
		unsigned long DatabaseInfo::GetMaxElementID()
		{
			ASSERT( m_ResPtr != NULL );
			
			return m_ResPtr->GetLong( _T("MaxElementID") );
		}
		
		void DatabaseInfo::SetMaxElementID( unsigned long lID )
		{
			ASSERT( m_ResPtr != NULL );
			
			m_ResPtr->SetLong( _T("MaxElementID"), lID );
		}
		
		void DatabaseInfo::SetWorldID( unsigned long lID )
		{
			ASSERT( m_ResPtr != NULL );

			m_ResPtr->SetLong( _T("WorldID"), lID );
		}

		UESoft::ErrorStatus DatabaseInfo::Close()
		{
			DatabaseElement::Close();
			if ( m_ResPtr != NULL )
			{
				m_ResPtr->Close();
				m_ResPtr = NULL;
			}
			return UESoft::eOk;
		}

		UESoft::ErrorStatus DatabaseInfo::Update()
		{
			ASSERT( m_ResPtr != NULL );

			m_ResPtr->BatchUpdate();

			return UESoft::eOk;
		}
	}
}
